package com.yonyou.pmclouds.async;

import com.yonyou.pmclouds.basecom.async.AsyncInvocation;
import com.yonyou.pmclouds.basecom.async.AsyncInvocationInfo;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class DefaultAsyncInvocationFactory implements AsyncInvocation.AsyncInvocationFactory {
    @Override
    public AsyncInvocation createInvocationFromInfo(AsyncInvocationInfo info) {
        try {
            Class<?> invocationClz = Class.forName(info.getExecutionClass());
            Constructor<?> constructor = invocationClz.getConstructor(AsyncInvocationInfo.class);
            return (AsyncInvocation) constructor.newInstance(info);
        } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
            return null;
        }
    }
}
